<?php
//namespace student\controller\welcome;
defined('BASEPATH') OR exit('No direct script access allowed');

class Index extends CI_Controller {


	public function __construct()
	{
		parent::__construct();
		//$this->load->model('');
		$this->load->helper('url_helper');
		//$this->load->library('captcha');
		session_start();
	}

    /**
    *  首页展示
    */
	public function index()
	{
		$this->load->view('index');
	}


	/**
     *  验证用户登录函数
	*/
	public function verifyLogin()
	{
		//获取页面提交数据：用户名、密码、验证码
		$username = @$_REQUEST['username']?$_REQUEST['username']:"";
		$password = @$_REQUEST['password']?$_REQUEST['password']:"";
		$captcha = @$_REQUEST['captcha']?$_REQUEST['captcha']:'';
		

		//验证用户名和密码为空
		/*if($captcha != $_SESSION['code'] || $captcha == '')
		{
			print json_encode(array('code'=>1,'desc'=>'验证码输入错误','text'=>$_SESSION['code'],'te'=>$captcha));
			return 0;
		}*/

		if($username == '' || $password == '')
		{
			print json_encode(array('code'=>2,'desc'=>'用户名或密码为空'));
			return 0;
		}

        $this->load->model("getuser");

        $resUser = $this->getuser->verifyLogin($username,$password);

        //验证用户名和密码正确性
        if(@$resUser[0])
        {
        	$_SESSION['username'] = $username;
        	print json_encode(array('code'=>0,'desc'=>'登录成功'));
        } else {
        	print json_encode(array('code'=>3,'desc'=>'用户名或密码错误'));
        }


	}

}
